package com.aiti.lulian.service.impl;

import com.aiti.base.core.base.service.iml.BaseSerivceImpl;
import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.entity.CardHolder;
import com.aiti.lulian.mapper.CardHolderMapper;
import com.aiti.lulian.service.CardHolderService;
import com.aiti.lulian.vo.CardHolderVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CardHolderServiceImpl extends BaseSerivceImpl<CardHolderMapper, CardHolder> implements CardHolderService {

    @Autowired
    private CardHolderMapper cardHolderMapper;

    @Override
    public List<CardHolderVo> findCardHolderListByBaseId(String baseId) {
        return cardHolderMapper.findCardHolderListByBaseId(baseId);
    }

    @Override
    public CardHolderVo findCardHolderListById(String baseId, String cardHolderUserId) {
        return cardHolderMapper.findCardHolderById(baseId,cardHolderUserId);
    }

    @Override
    public void deleteCardHolder(String baseId, String cardHolderUserId) {
        cardHolderMapper.deleteCardHolder(baseId,cardHolderUserId);
    }

    @Override
    public Message getIsCollected(String userHolderCardId, String userCardId) {
        List<CardHolder> cardHolders = cardHolderMapper.selectList(new LambdaQueryWrapper<CardHolder>().eq(CardHolder::getUserHolderCardId, userHolderCardId).eq(CardHolder::getUserCardId, userCardId));
        if (cardHolders.size() > 0) {
            return Message.success(true);
        } else {
            return Message.success(false);
        }
    }
}
